package com.tmz.cloudmall.cloudmallware.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tmz.cloudmall.cloudmallware.domain.PurchaseDetail;
import com.tmz.cloudmall.cloudmallware.service.IPurchaseDetailService;
import com.tmz.cloudmall.cloudmallcommon.common.annotation.Log;
import com.tmz.cloudmall.cloudmallcommon.common.core.controller.BaseController;
import com.tmz.cloudmall.cloudmallcommon.common.core.domain.AjaxResult;
import com.tmz.cloudmall.cloudmallcommon.common.core.page.TableDataInfo;
import com.tmz.cloudmall.cloudmallcommon.common.enums.BusinessType;
import com.tmz.cloudmall.cloudmallcommon.common.utils.poi.ExcelUtil;

/**
 * 购货详情Controller
 * 
 * @author tmz
 * @date 2025-08-16
 */
@RestController
@RequestMapping("/cloudmallware/purchaseDetail")
public class PurchaseDetailController extends BaseController
{
    @Autowired
    private IPurchaseDetailService purchaseDetailService;

    /**
     * 查询购货详情列表
     */
    @PreAuthorize("@ss.hasPermi('cloudmallware:purchaseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseDetail purchaseDetail)
    {
        startPage();
        List<PurchaseDetail> list = purchaseDetailService.selectPurchaseDetailList(purchaseDetail);
        return getDataTable(list);
    }

    /**
     * 导出购货详情列表
     */
    @PreAuthorize("@ss.hasPermi('cloudmallware:purchaseDetail:export')")
    @Log(title = "购货详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseDetail purchaseDetail)
    {
        List<PurchaseDetail> list = purchaseDetailService.selectPurchaseDetailList(purchaseDetail);
        ExcelUtil<PurchaseDetail> util = new ExcelUtil<PurchaseDetail>(PurchaseDetail.class);
        util.exportExcel(response, list, "购货详情数据");
    }

    /**
     * 获取购货详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloudmallware:purchaseDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purchaseDetailService.selectPurchaseDetailById(id));
    }

    /**
     * 新增购货详情
     */
    @PreAuthorize("@ss.hasPermi('cloudmallware:purchaseDetail:add')")
    @Log(title = "购货详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseDetail purchaseDetail)
    {
        return toAjax(purchaseDetailService.insertPurchaseDetail(purchaseDetail));
    }

    /**
     * 修改购货详情
     */
    @PreAuthorize("@ss.hasPermi('cloudmallware:purchaseDetail:edit')")
    @Log(title = "购货详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseDetail purchaseDetail)
    {
        return toAjax(purchaseDetailService.updatePurchaseDetail(purchaseDetail));
    }

    /**
     * 删除购货详情
     */
    @PreAuthorize("@ss.hasPermi('cloudmallware:purchaseDetail:remove')")
    @Log(title = "购货详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchaseDetailService.deletePurchaseDetailByIds(ids));
    }
}
